#ifndef SOCKET_H
#define SOCKET_H

#include <windows.h>
#include <winsock2.h>

#include <string>
#include <sstream>

#define MAXCONNECTIONS 5

using namespace std;

namespace network {
	template <
		class blocking_policy, 
		class locking_policy,
		class error_policy
	>
	class socket : public blocking_policy, 
		       public locking_policy, 
		       public error_policy {
	public:
		socket();
		socket(const string &addr, int port);
		~socket();

		string read();
		void write(const string &str);

		bool listen() const;
		bool bind(int port);
		template <class socket_rhs>
		bool accept(socket_rhs &sock) const;
	private:
		SOCKET _sock;
		SOCKADDR_IN _serv;
	};
}

#include "socket.tpl"
#endif

